home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / tools / czesc_2 / makepatch / sources / patchem.asm < prev   
Assembly Source File  |  1993-02-11  |  15KB  |  439 lines

  1. ;****** Auto-Revision Header (do not edit) *******************************
  2. ;*
  3. ;* © Copyright by PetiWare
  4. ;*
  5. ;* Filename         : PatchEm.asm
  6. ;* Created on       : 24-Jan-93
  7. ;* Created by       : Peter Simons
  8. ;* Current revision : V0.004
  9. ;*
  10. ;*
  11. ;* Purpose: Patched ein altes File zu einem neuen um, unter Verwendung
  12. ;*          der mit MakePatch erstellten Daten.
  13. ;*
  14. ;*
  15. ;* V0.004 : Nachdem das gepatchte File erzeugt wurde, wird ebenfalls die
  16. ;*          CRC-Prüfsumme verglichen, um Fehler zu vermeiden!
  17. ;*
  18. ;* V0.003 : Nach dem Laden wird die OriginalCRC mit der im PatchFile
  19. ;*          angegebenen verglichen und bei Verschiedenheit abgebrochen!
  20. ;*
  21. ;* V0.002 : Patch'Em auf das neue FileFormat umgestellt.
  22. ;*
  23. ;* V0.001 : Basiert auf dem Programmgerüst von MakePatch.
  24. ;*
  25. ;* V0.000 : --- Initial release ---
  26. ;*
  27. ;*************************************************************************
  28. ;
  29. ;
  30. ;
  31.  
  32. ;***************************************************************************
  33. ;*                                                                         *
  34. ;* SEKTION: Labels, Macros, Switches, Structures                           *
  35. ;*                                                                         *
  36. ;***************************************************************************
  37.  
  38. ;-------------------------------------- Switches -----------
  39.                 MC68000
  40.                 NEWSYNTAX
  41.                 EXEOBJ
  42.                 OBJFILE "RAM:PatchEm"
  43.                 DEBUG on
  44.                 SYM
  45.                 MULTIPASS
  46. ;               VERBOSEOPTIM
  47.  
  48. ;-------------------------------------- Structures --------
  49. PatchChunk      CLRSO
  50. pc_DataType     SO.w    1
  51. pc_ChunkLen     SO.l    1
  52. pc_ChunkData    SOVAL
  53. pc_SIZEOF       SOVAL
  54.  
  55. PatchFile       CLRSO
  56. pf_PatchedSize  SO.l    1
  57. pf_OrigCRC      SO.w    1
  58. pf_PatchedCRC   SO.w    1
  59. pf_PatchData    SOVAL
  60.  
  61. ;-------------------------------------- Labels ------------
  62.                 MACLIB  "DATAS:Includes.preass"
  63.                 MACLIB  "DATAS:Offsets.preass"
  64.                 MACFILE "A:Sources/PetiToolLibrary/PToolLibrary.i"
  65.  
  66. KICKVERSION     equ     37
  67.  
  68. ;-------------------------------------- Datatypes ---------
  69. DT_NOMOREDATA   equ     0
  70. DT_ORIGINAL     equ     1
  71. DT_PATCHED      equ     2
  72. DT_SKIPPED      equ     3
  73. DT_INSERTED     equ     4
  74.  
  75. ;-------------------------------------- Macros ------------
  76. REVISION        MACRO
  77.                 dc.b "0.004"
  78.                 ENDM
  79. REVDATE         MACRO
  80.                 dc.b "11-Feb-93"
  81.                 ENDM
  82. PUSHM           MACRO
  83. saveregs        setrl   \1
  84.                 movem.l saveregs,-(SP)
  85.                 ENDM
  86. POPM            MACRO
  87.                 movem.l (SP)+,saveregs
  88.                 ENDM
  89.  
  90.  
  91. ;***************************************************************************
  92. ;*                                                                         *
  93. ;* SEKTION: Programm                                                       *
  94. ;*                                                                         *
  95. ;***************************************************************************
  96.  
  97. ;---------------------- Systemumgebung initialisieren ---------------------
  98. START:          lea     (DATA_Seg,PC),a5
  99.                 BASEREG a5,DATA_Seg
  100.  
  101.                 lea     (ptoollibname,PC),a1
  102.                 moveq   #1,d0
  103.                 move.l  ($4).W,a6
  104.                 jsr     (_LVOOpenLibrary,a6)
  105.                 move.l  d0,(_PToolBase)
  106.                 bne.b   .PToolLibOkay
  107.                 bsr     _NoPToolLibrary
  108.                 bra     .Exit
  109. .PToolLibOkay   move.l  d0,a6
  110.                 move.l  (ptl_DOSBase,a6),(_DOSBase)
  111.  
  112.                 move.l  #CCF_OS_VERSION,d0
  113.                 move.w  #KICKVERSION,d1
  114.                 jsr     (_LVOCheckConfig,a6)
  115.                 tst.l   d0
  116.                 beq.b   .ConfigOkay
  117.                 lea     (PrgName,PC),a0
  118.                 moveq   #0,d2
  119.                 jsr     (_LVODisplayConfigErrorDos,a6)
  120.                 bra     .ClosePToolLib
  121. .ConfigOkay
  122. ;------------------------------ Argument-Parsing --------------------------
  123.                 lea     (RDArgsTemplate,PC),a0
  124.                 move.l  a0,d1
  125.                 lea     (_Original,PC),a0
  126.                 move.l  a0,d2
  127.                 moveq   #0,d3
  128.                 move.l  (_DOSBase,PC),a6
  129.                 jsr     (_LVOReadArgs,a6)
  130.                 move.l  d0,(_RDArgsStruct)
  131.                 bne.b   .RDArgsOkay
  132.                 moveq   #0,d0
  133.                 moveq   #0,d1
  134.                 lea     (PrgName,PC),a0
  135.                 move.l  (_PToolBase,PC),a6
  136.                 jsr     (_LVOErrorHandleDos,a6)
  137.                 bra     .ClosePToolLib
  138. .RDArgsOkay
  139. ;----------------------------- Puffer reservieren -------------------------
  140.                 move.l  (_Original,PC),a0
  141.                 move.l  (_PToolBase,PC),a6
  142.                 jsr     (_LVOLoadFile,a6)
  143.                 move.l  d0,(_SourceBuffer)
  144.                 bne.b   .SourceOkay
  145.                 moveq   #1,d0
  146.                 move.l  (_Original,PC),-(SP)
  147.                 move.l  SP,a1
  148.                 bsr     _ErrorHandle
  149.                 addq.w  #4,SP
  150.                 bra     .FreeRDArgs
  151.  
  152. .SourceOkay     move.l  (_PatchFile,PC),a0
  153.                 jsr     (_LVOLoadFile,a6)
  154.                 move.l  d0,(_PatchBuffer)
  155.                 bne.b   .PatchOkay
  156.                 moveq   #1,d0
  157.                 move.l  (_NewVersion,PC),-(SP)
  158.                 move.l  SP,a1
  159.                 bsr     _ErrorHandle
  160.                 addq.w  #4,SP
  161.                 bra     .FreeTargetBuffer
  162.  
  163. .PatchOkay      move.l  (_PatchBuffer,PC),a0
  164.                 move.l  (4+pf_PatchedSize,a0),d2
  165.                 move.l  d2,d0
  166.                 move.l  #MEMF_PUBLIC,d1
  167.                 move.l  ($4).w,a6
  168.                 jsr     (_LVOAllocVec,a6)
  169.                 move.l  d0,(_TargetBuffer)
  170.                 bne.b   .TargetOkay
  171.                 moveq   #2,d0
  172.                 pea     (PublicMemStr,PC)
  173.                 move.l  d2,-(SP)
  174.                 move.l  SP,a1
  175.                 bsr     _ErrorHandle
  176.                 addq.w  #8,SP
  177.                 bra     .FreeSourceBuffer
  178. .TargetOkay
  179. ;------------------------------- CRC vergleichen --------------------------
  180.                 move.l  (_SourceBuffer,PC),a0
  181.                 move.l  (a0)+,d0
  182.                 move.l  (_PToolBase,PC),a6
  183.                 jsr     (_LVOCRC16Buffer,a6)
  184.                 move.l  (_PatchBuffer,PC),a0
  185.                 cmp.w   (4+pf_OrigCRC,a0),d0
  186.                 beq.b   .SourceCRCOkay
  187.                 moveq   #11,d0
  188.                 pea     (SourceCRCFalse,PC)
  189.                 move.l  SP,a1
  190.                 bsr     _ErrorHandle
  191.                 addq.w  #4,SP
  192.                 bra     .FreeSourceBuffer
  193. .SourceCRCOkay
  194. ;------------------------------ Patch erstellen ---------------------------
  195.                 move.l  (_SourceBuffer,PC),a0
  196.                 addq.w  #4,a0
  197.                 move.l  (_TargetBuffer,PC),a1
  198.                 move.l  (_PatchBuffer,PC),a2
  199.                 add.w   #pf_PatchData+4,a2
  200.                 bsr     _PatchData
  201.  
  202. ;------------------------------- CRC vergleichen --------------------------
  203.                 move.l  (_PatchBuffer,PC),a0
  204.                 move.l  (4+pf_PatchedSize,a0),d0
  205.                 move.l  (_TargetBuffer,PC),a0
  206.                 move.l  (_PToolBase,PC),a6
  207.                 jsr     (_LVOCRC16Buffer,a6)
  208.                 move.l  (_PatchBuffer,PC),a0
  209.                 cmp.w   (4+pf_PatchedCRC,a0),d0
  210.                 beq.b   .TargetCRCOkay
  211.                 moveq   #11,d0
  212.                 pea     (TargetCRCFalse,PC)
  213.                 move.l  SP,a1
  214.                 bsr     _ErrorHandle
  215.                 addq.w  #4,SP
  216.                 bra     .FreeSourceBuffer
  217. .TargetCRCOkay
  218. ;----------------------------- ZielPuffer speichern -----------------------
  219.                 move.l  (_NewVersion,PC),d1
  220.                 move.l  #MODE_NEWFILE,d2
  221.                 move.l  (_DOSBase,PC),a6
  222.                 jsr     (_LVOOpen,a6)
  223.                 ERRORHANDLE d5,0,(.FreePatchBuffer,PC)
  224.  
  225.                 move.l  d5,d1
  226.                 move.l  (_TargetBuffer,PC),d2
  227.                 move.l  (_PatchBuffer,PC),a0
  228.                 move.l  (4+pf_PatchedSize,a0),d3
  229.                 move.l  (_PToolBase,PC),a6
  230.                 jsr     (_LVOSaveBreak,a6)
  231.                 cmp.l   #-1,d0
  232.                 bne.b   .CloseDestFile
  233.                 move.l  (_DOSBase,PC),a6
  234.                 jsr     (_LVOIoErr,a6)
  235.                 tst.l   d0
  236.                 bne.b   .SaveError
  237.                 bsr     _BreakError
  238. .SaveError      moveq   #11,d0
  239.                 pea     (SaveError,PC)
  240.                 move.l  SP,a1
  241.                 bsr     _ErrorHandle
  242.                 addq.w  #4,SP
  243.  
  244. .CloseDestFile  move.l  d5,d1
  245.                 move.l  (_DOSBase,PC),a6
  246.                 jsr     (_LVOClose,a6)
  247.  
  248. ;-------------------------- Systemumgebung freigeben ----------------------
  249. .FreePatchBuffer:
  250.                 move.l  (_PatchBuffer,PC),a1
  251.                 move.l  ($4).w,a6
  252.                 jsr     (_LVOFreeVec,a6)
  253.  
  254. .FreeTargetBuffer:
  255.                 move.l  (_TargetBuffer,PC),a1
  256.                 move.l  ($4).w,a6
  257.                 jsr     (_LVOFreeVec,a6)
  258.  
  259. .FreeSourceBuffer:
  260.                 move.l  (_SourceBuffer,PC),a1
  261.                 move.l  ($4).w,a6
  262.                 jsr     (_LVOFreeVec,a6)
  263.  
  264. .FreeRDArgs     move.l  (_RDArgsStruct,PC),d1
  265.                 beq.b   .ClosePToolLib
  266.                 move.l  (_DOSBase,PC),a6
  267.                 jsr     (_LVOFreeArgs,a6)
  268.  
  269. .ClosePToolLib  move.l  (_PToolBase,PC),a1
  270.                 move.l  ($4).W,a6
  271.                 jsr     (_LVOCloseLibrary,a6)
  272.  
  273. .Exit           moveq   #0,d0
  274.                 rts
  275.  
  276. ;***************************************************************************
  277. ;*                                                                         *
  278. ;* SEKTION: Unterroutinen                                                  *
  279. ;*                                                                         *
  280. ;***************************************************************************
  281.  
  282. ;-------------------------------- Patchgeneration -------------------------
  283. _PatchData:
  284.                 ; Erstellt aus dem Patch- und dem Originalfile das Zielfile.
  285.                 ;
  286.                 ; Parameter: A0=&Original A1=&Target A2=&PatchBuffer
  287.                 ; Result   : D0=PatchLength
  288.  
  289.                 PUSHM   d2-d7/a2-a4/a6
  290.                 lea     (.DataTypeTab,PC),a3
  291.                 moveq   #0,d7
  292.  
  293. ...             move.w  (pc_DataType,a2),d0
  294.                 beq.b   .exit
  295.                 lsl.w   #1,d0
  296.                 lea     (a3,d0.w),a4
  297.                 add.w   (a4),a4
  298.                 jsr     (a4)
  299.                 bra.b   ...
  300.  
  301.  
  302. .exit           move.l  d7,d0
  303.                 POPM
  304.                 rts
  305.  
  306. .Original       move.l  (pc_ChunkLen,a2),d0
  307.                 addq.w  #pc_SIZEOF,a2
  308.                 bra     _CopyBlock
  309.  
  310. .Patched        rts                     ; Not supportet yet
  311.  
  312. .Skipped        add.l   (pc_ChunkLen,a2),a0
  313.                 addq.w  #pc_SIZEOF,a2
  314.                 rts
  315.  
  316. .Inserted       move.l  (pc_ChunkLen,a2),d0
  317.                 lea     (pc_ChunkData,a2),a2
  318.                 exg.l   a2,a0
  319.                 bsr     _CopyBlock
  320.                 exg.l   a2,a0
  321.                 btst    #0,d0
  322.                 beq.b   .NotOdd
  323.                 addq.w  #1,a2
  324. .NotOdd         rts
  325.  
  326.  
  327. .DataTypeTab    dc.w    0                       ; DT_NOMOREDATA
  328.                 dc.w    .Original-*             ; DT_ORIGINAL
  329.                 dc.w    .Patched-*              ; DT_PATCHED
  330.                 dc.w    .Skipped-*              ; DT_SKIPPED
  331.                 dc.w    .Inserted-*             ; DT_INSERTED
  332.  
  333. _CopyBlock:     move.l  d0,-(SP)
  334.                 beq.b   .exit
  335. ...             move.b  (a0)+,(a1)+
  336.                 subq.l  #1,d0
  337.                 bne.b   ...
  338. .exit           move.l  (SP)+,d0
  339.                 rts
  340.  
  341.  
  342.  
  343. ;-------------------------------- Fehlerhandhabung ------------------------
  344. _BreakError:
  345.                 ; Gibt den "Received CTRL/C"-String aus
  346.                 ;
  347.                 ; Parameter: keine
  348.                 ; Result   : keins
  349.  
  350.                 PUSHM   d0-d1/a0-a1/a6
  351.                 lea     (PrgName,PC),a0
  352.                 moveq   #0,d1
  353.                 moveq   #5,d0
  354.                 move.l  (_PToolBase,PC),a6
  355.                 jsr     (_LVOErrorHandleDos,a6)
  356.                 POPM
  357.                 rts
  358.  
  359. _ErrorHandle:
  360.                 ; Erzeut über ErrorHandleIntuition() die Fehlermeldung.
  361.                 ;
  362.                 ; Parameter: A1=&DataFlow D0=Errornumber
  363.                 ; Result   : keins
  364.  
  365.                 PUSHM   d0-d1/a0-a2/a6
  366.                 lea     (PrgName,PC),a0
  367.                 sub.l   a2,a2
  368.                 move.l  (_PToolBase,PC),a6
  369.                 jsr     (_LVOErrorHandleIntuition,a6)
  370.                 POPM
  371.                 rts
  372.  
  373.  
  374. _NoPToolLibrary:
  375.                 ; Gibt einen Fehler aus, falls die PTool.Library nicht ge-
  376.                 ; öffnet werden konnte.
  377.                 ;
  378.                 ; Parameter: keine
  379.                 ; Result   : keins
  380.  
  381.                 lea     (dosname,PC),a1
  382.                 move.l  ($4).W,a6
  383.                 jsr     (_LVOOldOpenLibrary,a6)
  384.                 tst.l   d0
  385.                 beq.b   .exit
  386.                 move.l  d0,a6
  387.                 jsr     (_LVOOutput,a6)
  388.                 move.l  d0,d1
  389.                 beq.b   .CloseDosLib
  390.                 lea     (PrgName,PC),a0
  391.                 move.l  a0,d2
  392.                 moveq   #NoPToolError_len,d3
  393.                 jsr     (_LVOWrite,a6)
  394. .CloseDosLib    move.l  a6,a1
  395.                 move.l  ($4).W,a6
  396.                 jsr     (_LVOCloseLibrary,a6)
  397. .exit           rts
  398.  
  399.  
  400.  
  401. ;***************************************************************************
  402. ;*                                                                         *
  403. ;* SEKTION: Daten                                                          *
  404. ;*                                                                         *
  405. ;***************************************************************************
  406. DATA_Seg:
  407.                 dc.b    "$VER: "
  408. PrgName         dc.b    "Patch'Em v"
  409.                 REVISION
  410.                 dc.b    " ("
  411.                 REVDATE
  412.                 dc.b    ")"
  413.                 dc.b    0
  414.                 dc.b    " requires the PTool.Library!!",$0A,$0A
  415. NoPToolError_len equ (*-PrgName)
  416.  
  417. ptoollibname    CSTR    "ptool.library"
  418. dosname         CSTR    "dos.library"
  419. PublicMemStr    CSTR    "PublicMem"
  420. RDArgsTemplate  CSTR    "Original/A,NewVersion/A,PatchFile/A"
  421. PatchTooLong    CSTR    "Sorry, but the patch would have been longer, than the new-version!"
  422. SaveError       CSTR    "File couldn't been saved succesfully!"
  423. SourceCRCFalse  CSTR    "Sorry, but the patch wasn't made for that sourcefile!"
  424. TargetCRCFalse  CSTR    "INTERNAL ERROR!! Please report to the author!"
  425.  
  426.                 CNOP    0,4
  427. _PToolBase      ds.l    1
  428. _DOSBase        ds.l    1
  429. _RDArgsStruct   ds.l    1
  430. _SourceBuffer   ds.l    1
  431. _TargetBuffer   ds.l    1
  432. _PatchBuffer    ds.l    1
  433.  
  434. _Original       ds.l    1                       ; Array für ReadArgs()
  435. _NewVersion     ds.l    1
  436. _PatchFile      ds.l    1
  437.  
  438.                 END
  439.